﻿using System;
using System.Collections.Generic;
using System.Text;
using LBoL.Base;
using LBoL.Base.Extensions;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Cards;
using LBoL.Core.StatusEffects;
using LBoL.Core.Units;
using LBoL.EntityLib.Cards.Character.Marisa;
using LBoL.EntityLib.Cards.Neutral.Blue;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;

namespace ProbeMod.Cards
{
    public sealed class ProbeGoldenArmadaSupportDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            var config = GetCardDefaultConfig();

            config.TargetType = TargetType.Nobody;
            config.Type = CardType.Skill;
            config.Rarity = Rarity.Uncommon;

            config.Colors = new List<ManaColor>() { ManaColor.White };
            config.Cost = new ManaGroup() { White = 3 };

            config.UpgradedKeywords = Keyword.Debut;

            config.IsXCost = true;

            config.RelativeCards = new List<string>() { "ProbeCarrier", "ProbeTempest", "ProbeMothership" };
            config.UpgradedRelativeCards = new List<string>() { "ProbeCarrier", "ProbeTempest", "ProbeMothership" };
            config.Index = CardIndexGenerator.GetUniqueIndex(config);

            return config;
        }
    }

    /// <summary>
    /// 黄金舰队支援
    /// WWWX
    /// 将1航母置入手牌
    /// 每支付3：将风暴战舰置入手牌
    /// 每支付9：召唤强大的母舰，随后放逐黄金舰队支援
    /// </summary>
    [EntityLogic(typeof(ProbeGoldenArmadaSupportDef))]
    public sealed class ProbeGoldenArmadaSupport : ProbeCard
    {
        protected override string GetBaseDescription()
        {
            if (base.DebutActive || !IsUpgraded)
            {
                return base.GetBaseDescription();
            }
            return base.GetExtraDescription1;
        }

        // 获取X费
        public override ManaGroup GetXCostFromPooled(ManaGroup pooledMana)
        {
            return pooledMana;
        }

        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            //  给航母
            yield return new AddCardsToHandAction(Library.CreateCard<ProbeCarrier>());

            if (base.TriggeredAnyhow)
            {
                yield return new GainManaAction(new ManaGroup() { White=2 });
            }


            // 算数量
            int count = SynergyAmount(consumingMana, ManaColor.Any);
            var tempest = count / 3;
            var mothership = count / 9;
            // 给牌
            yield return new AddCardsToHandAction(Library.CreateCards<ProbeTempest>(tempest));

            var mothershipCards = Library.CreateCards<ProbeMothership>(mothership);
            foreach (var item in mothershipCards)
            {
                item.Summon();
            }

            yield return new AddCardsToHandAction(mothershipCards);
            // 消耗
            if (mothership > 0)
            {
                yield return new ExileCardAction(this);
            }
        }
    }
}
